package uk.ac.aber.paws.server.autosleep;

import uk.ac.aber.paws.server.core.PAWSServer;
import uk.ac.aber.paws.server.db.DBLogger;
import uk.ac.aber.paws.server.util.TimeChecks;
import java.util.*;
import java.util.logging.Level;

/**
 * @author Rob Johnson, Aberystwyth University
 * @email rob.johnson@aber.ac.uk
 * @date 16th August 2011
 * 
 * SleepMonitor.java
 * 
 * Contains all generic constants used within the application
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class SleepMonitor {

	private	static Vector<Hashtable<String,Object>> profiles;
	
	/**
	 * Invokes the processing of the power profiles. Performs a query to the database and invokes a new instance
	 * of ProfileProcessor for each profile extracted from the database.
	 */
	public static void processProfiles() {
		
		try {
				
			// retrieve the power management profile information from the database
			profiles = (new DBLogger().getAllProfiles());
			
			PAWSServer.LOG_FILE.log(Level.INFO,"Number of power profiles to process: "+profiles.size());
			
			// for each profile listed in the database
			for (int i=0;i<profiles.size();i++) {
				
				// populate top level class with profile info
				Hashtable<String,Object> thisProfile = profiles.get(i);
				
				PAWSServer.LOG_FILE.log(Level.INFO,"Profile: "+thisProfile.toString());
				
				new ProfileProcessor(thisProfile);
			}
			
		}
		catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}
